package com.data.app.dao.pg;

import com.data.app.commons.constant.CommonConstant;
import com.data.app.pojo.pg.CityHouseEntity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDate;
import java.util.List;

public interface CityHouseBaseDao extends JpaRepository<CityHouseEntity, String> {

    // @Query(nativeQuery = true, value = "select * from "+ CommonConstant.TABLE_NAME_CITY_HOUSE)
    // List<CityHouseEntity> findAllByLimit(String city);
    @Query(nativeQuery = true, value = "select * from "+ CommonConstant.TABLE_NAME_CITY_HOUSE +" where province=:city")
    List<CityHouseEntity> findAllByLimit(String city);
    /**
     * 查询该时间段内的新增数据
     * @param startDate
     * @param endDate
     * @return
     */
    @Query(nativeQuery = true, value = "select * from "+ CommonConstant.TABLE_NAME_CITY_HOUSE +" WHERE CAST(create_time AS  DATE) BETWEEN DATE(:startDate) and DATE(:endDate)")
    List<CityHouseEntity> findCityHouseAddByDate(@Param(value = "startDate") LocalDate startDate, @Param(value = "endDate") LocalDate endDate);

    /**
     * 查询时间段内修改数据
     * @param startDate
     * @param endDate
     * @return
     */
    @Query(nativeQuery = true, value = "select * from "+ CommonConstant.TABLE_NAME_CITY_HOUSE +" WHERE create_time!=update_time and  CAST(update_time AS  DATE) BETWEEN DATE(:startDate) and DATE(:endDate)")
    List<CityHouseEntity> findCityHouseUpdateByDate(@Param(value = "startDate") LocalDate startDate,@Param(value = "endDate") LocalDate endDate);

}
